//放置所以关于axios的配置
// 设置根路径
axios.defaults.baseURL = 'http://big-event-api-t.itheima.net'

// 请求拦截器
axios.interceptors.request.use(config => {
    // Do something before request is sent
    // 判断请求url地址是否包含/my  有就在请求头上加上token
    if (config.url.indexOf('/my') !== -1) {
        config.headers.Authorization = localStorage.getItem('big-event-token')
    }
    return config;
}, error => {
    // Do something with request error
    return Promise.reject(error);
});


// 响应拦截器git 
axios.interceptors.response.use(response => {
    // Do something before response is sent
    // 判断如果不合法的会  回到login页面
    // console.log(response);
    if (response.data.status === 1 && response.data.message === '身份认证失败！') {
        location.href = '/login.html'

    }

    return response;
}, error => {
    // Do something with response error
    return Promise.reject(error);
});